package com.party.mobile.biz.order;

import com.party.core.model.order.OrderForm;
import com.party.mobile.biz.order.payOrder.IPayOrderService;
import com.party.mobile.biz.order.payOrder.PayOrderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * @ClassName OrderBizNewService
 * @Description 新版支付回调
 * @Author yifeng
 * @Date 2019/4/10 11:56
 **/
@Service
public class OrderBizNewService {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private PayOrderFactory payOrderFactory;

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void updatePayBusiness(OrderForm orderForm, Object object, Integer paymentWay) {
        IPayOrderService payOrderService = payOrderFactory.buildPayOrder(orderForm.getType());
        try {
            payOrderService.doPay(orderForm, object, paymentWay);
        } catch (Exception e) {
            logger.error("支付回调异常", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw e;
        }
    }
}
